/**
* 参考地址：http://docs.jquery.com/Plugins/Authoring
*
*/
(function( $ ){
	/**
	 * 调用方法:$('#element').myPlugin();
	 */
  $.fn.myPlugin = function() {
  
    // there's no need to do $(this) because
    // "this" is already a jquery object

    // $(this) would be the same as $($('#element'));
        
    this.fadeIn('normal', function(){

      // the this keyword is a DOM element

    });

  };
  /**
  * 调用方法: var tallest = $('div').maxHeight(); 
  */
  $.fn.maxHeight = function() {
  
    var max = 0;

    this.each(function() {
      max = Math.max( max, $(this).height() );
    });

    return max;
  };
  /**
  * 调用方法: 
  * $('div').lockDimensions('width').css('color', 'red');
  */
  $.fn.lockDimensions = function( type ) {  

    return this.each(function() {

      var $this = $(this);

      if ( !type || type == 'width' ) {
        $this.width( $this.width() );
      }

      if ( !type || type == 'height' ) {
        $this.height( $this.height() );
      }

    });

  };
  
  /**
  * 调用方法:
  * $('div').tooltip({
  *   'location' : 'left'
  * });
  */
  $.fn.tooltip = function( options ) { 

    // Create some defaults, extending them with any options that were provided
    var settings = $.extend( {
      'location'         : 'top',
      'background-color' : 'blue'
    }, options);

    return this.each(function() {
      // Tooltip plugin code here
    });
  };

  var methods = {
    init : function( options ) {
      // THIS 
    },
    show : function( ) {
      // IS
    },
    hide : function( ) {
      // GOOD
    },
    update : function( content ) {
    }
  }

  $.fn.tooltip = function( method ) {    
    // Method calling logic
    if ( methods[method] ) {
      return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
    } else if ( typeof method === 'object' || ! method ) {
      return methods.init.apply( this, arguments );
    } else {
      $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
    }  
  };
})( jQuery );